# coding: utf8
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from .utils.JsonEncoder import JsonEncoder

db = SQLAlchemy()
ma = Marshmallow()
jd = JsonEncoder(db)


def create_app(config):
    app = Flask(__name__)
    with app.app_context():
        app.config.from_object(config)
        db.init_app(app)
        ma.init_app(app)
        '''
        注册路由
        '''
        from .routes import api_blueprint, main_blueprint, upload_blueprint
        app.register_blueprint(main_blueprint)
        app.register_blueprint(api_blueprint, url_prefix='/api')
        from .routes.upload import init_upload
        init_upload(app)
    return app